import net from 'net'
export const website = 'http://47.106.80.184'

let baseUrl = process.env.BASE_URL
// export const target = baseUrl.indexOf('sass') !== -1?'users': 'platform'
// export const target = 'users'
export const target = 'platform'

// 内容类型: 1视频 2图片 3文档 4应用程序 5网页应用 6电脑桌面 7其他
const suffixFileMap = {
  tif: 2,
  svg: 2,
  jpg: 2,
  jpeg: 2,
  png: 2,
  gif: 2,
  bmp: 2,
  mp4: 1,
  avi: 1,
  dat: 1,
  dvr: 1,
  vcd: 1,
  mov: 1,
  svcd: 1,
  vob: 1,
  dvd: 1,
  dvtr: 1,
  bbc: 1,
  evd: 1,
  flv: 1,
  rmvb: 1,
  wmv: 1,
  mkv: 1,
  '3gp': 1,
  xlsx: 3,
  pdf: 3,
  ppt: 3,
  pptx: 3,
  xls: 3,
  doc: 3,
  docx: 3,
  docm: 3,
  dotx: 3,
  dotm: 3,
  ppsx: 3,
  pptm: 3,
  xps: 3
}

// 内容类型: 1视频 2图片 3文档 4应用程序 5网页应用 6电脑桌面 7其他 8节目 9流媒体
export const suffixFileMapStr = {
  1: '视频',
  2: '图片',
  3: '文档',
  4: '应用程序',
  5: '网页应用',
  6: '电脑桌面',
  7: '其他',
  8: '节目',
  9: '流媒体'
}

export const suffixFileMapObj = () => {
  let fileMapLabel = []
  Object.keys(suffixFileMapStr).forEach((key) => {
    let tmp = {
      label: suffixFileMapStr[key],
      value: key
    }
    fileMapLabel.push(tmp)
  })
  return fileMapLabel
}

export const mediaTypeMap = {
  movie: 1,
  picture: 2,
  office: 3,
  application: 4,
  web: 5,
  desktop: 6,
  other: 7,
  show: 8,
  stream: 9
}

export const mediaTypeStrMap = {
  1: "movie",
  2: "picture",
  3: "office",
  4: "application",
  5: "web",
  6: "desktop",
  7: "other",
  8: "show",
  9: "stream"
}

export const formatMediaType = (suffix) => {
  return suffixFileMap[suffix]?suffixFileMap[suffix]: 7
}

export const formatMediaTypeStr = (suffix) => {
  return suffixFileMapStr[suffix]
}

export const createTcpCon = () => {

  let socket
  const endpoint = 'ws://127.0.0.1:9191'; // WebSocket的地址
  socket = new WebSocket(endpoint);

  socket.send(JSON.stringify({"mode":"web","content":"http://www.baidu.com"}));
  socket.addEventListener('message', (event) => {
    // 处理服务器发送的消息
    console.log('完成', event.data);
  });

  return socket
}
